#coding=utf8
from werkzeug.security import check_password_hash
from . import db

# import pymysql
# from flask import Flask
# from flask_sqlalchemy import SQLAlchemy
#
# app = Flask(__name__)
# app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://root:chong@39.107.109.49:3390/triangle_server'
# app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True
# db = SQLAlchemy(app)

"""
create table if not exists user
(
    organization_name varchar(50) not null,
    official_accounts__name varchar(50) not null,
    person_name varchar(20) not null,
    person_num varchar(20) key,
    person_wechat_id varchar(50) not null,
    phone_num varchar(11) not null,
    password varchar(50) not null,
    register_time datetime not null
)engine=InnoDB default charset=utf8;
"""
class Publisher(db.Model):
	__tablename__ = 'publisher'
	organization_name = db.Column(db.String(50), nullable=False)
	official_accounts_name = db.Column(db.String(50), nullable=False)
	person_name = db.Column(db.String(20), nullable=False)
	person_num = db.Column(db.String(20), primary_key=True, index=True)
	person_wechat_id = db.Column(db.String(50), nullable=False)
	phone_num = db.Column(db.String(11), nullable=False)
	password = db.Column(db.String(100), nullable=False)
	register_time = db.Column(db.DateTime, nullable=False)

	# 记录内容发布者的状态信息，0表示未审核、1表示审核未通过、2表示审核通过
	state = db.Column(db.Integer, nullable=False, default=0)

	def __repr__(self):
		return "<User> %s %s" % (self.person_num, self.person_name)

	def checkpassword(self, password):
		return check_password_hash(self.password, password)

class Activity(db.Model):
	__tablename__ = 'activity'
	id = db.Column(db.String(35), primary_key=True, index=True)
	publisher_num = db.Column(db.String(20))
	title = db.Column(db.String(100), nullable=False)
	# 活动添加时间
	adding_time = db.Column(db.DateTime, nullable=False)
	# 活动截止日期
	closing_date = db.Column(db.Date, nullable=False)
	description = db.Column(db.Text, nullable=False)
	# activity_class = db.Column(db.String(10), nullable=False, index=True)
	logo = db.Column(db.String(100), nullable=False)
	article_url = db.Column(db.Text, nullable=False)
	remark = db.Column(db.Text, nullable=True)
	# state = db.Column(db.String(10), nullable=True)

	# 审核状态：0表示待审核、1表示已拒绝、2表示已通过
	new_state = db.Column(db.Integer, nullable=False, default=0, index=True)
	# 活动访问量
	count = db.Column(db.Integer, nullable=False, default=0, index=True)
	# 活动发布的组织名称
	organization_name = db.Column(db.String(50), nullable=False)
	# 管理员审核时间
	deal_time = db.Column(db.DateTime, nullable=True)
	# 活动分类。之前表示活动分类的字段是activity_class, activity_class直接用字符串保存互动分类，不利于升级
	new_activity_class = db.Column(db.Integer, nullable=False, default=0, index=True)



if __name__=='__main__':
	db.create_all()